<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="品牌名">
              <a-input placeholder="" v-model="queryParam.brandName" allowClear></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="编码">
              <a-input placeholder="" v-model="queryParam.brandCode" allowClear></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="default" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> -->
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table ref="table" size="middle" bordered rowKey="id" :columns="columns" :dataSource="dataSource"
        :pagination="ipagination" :loading="loading" class="j-table-force-nowrap" @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <!-- <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown> -->
        </span>
        <span slot="source" slot-scope="text, record">
          <span v-if="record.source == 2">自有</span>
          <span v-if="record.source == 3">平台</span>
        </span>
        <span slot="bizStatus" slot-scope="text, record">
          <a-switch v-model="record.bizStatus" @change="handleStatus(record)" />
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <brand-modal ref="modalForm" @ok="modalFormOk"></brand-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import BrandModal from './modules/BrandModal'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { postAction } from '@/api/manage'

export default {
  name: "BrandList",
  mixins: [JeecgListMixin],
  components: {
    BrandModal
  },
  data() {
    return {
      description: '品牌管理页面',
      // 表头
      columns: [
        {
          title: '品牌名',
          align: "center",
          dataIndex: 'brandName'
        },
        {
          title: '编码',
          align: "center",
          dataIndex: 'brandCode'
        },
        {
          title: '排序',
          align: "center",
          dataIndex: 'sort'
        },
        {
          title: '是否启用',
          align: "center",
          dataIndex: 'bizStatus',
          scopedSlots: { customRender: 'bizStatus' },
        },
        {
          title: '品牌logo',
          align: "center",
          dataIndex: 'photo'
        },
        {
          title: '类型',
          align: "center",
          dataIndex: 'source',
          scopedSlots: { customRender: 'source' },
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          scopedSlots: { customRender: 'action' },
        }
      ],
      url: {
        list: "/brand/brand/pageList",
        approve: "/brand/brand/approve",
      },
    }
  },
  computed: {
  },
  methods: {
    handleStatus(record) {
      this.loading = true
      let toModify = {id: record.id}
      toModify.bizStatus = record.bizStatus ? 1 : 0

      postAction(this.url.approve, [toModify])
        .then((res) => {
          if (res.success) {
            this.$message.success('操作成功')
          } else {
            this.$message.warn(res.message)
          }
        })
        .finally(() => (this.loading = false))
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>